package com.tech.zhidengxian.controller;

import com.tech.zhidengxian.model.constant.GoodsState;
import com.tech.zhidengxian.model.dto.CosDTO;
import com.tech.zhidengxian.model.dto.GoodsDTO;
import com.tech.zhidengxian.model.dto.page.MyPage;
import com.tech.zhidengxian.model.dto.request.GoodsRequest;
import com.tech.zhidengxian.model.dto.result.ReturnResult;
import com.tech.zhidengxian.model.dto.result.ReturnResultUtils;
import com.tech.zhidengxian.service.api.CosService;
import com.tech.zhidengxian.service.api.GoodsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @Resource
    private CosService cosService;
    @RequestMapping("/pageQueryRecommend")
    public ReturnResult<MyPage<GoodsDTO>> pageQueryRecommend(@RequestBody GoodsRequest goodsRequest){
        return ReturnResultUtils.returnSuccess(goodsService.pageQueryRecommend(goodsRequest));
    }

    @RequestMapping("/pageQueryLocalCity")
    public ReturnResult<MyPage<GoodsDTO>> pageQueryLocalCity(@RequestBody GoodsRequest goodsRequest){
        return ReturnResultUtils.returnSuccess(goodsService.pageQueryLocalCity(goodsRequest));
    }
    @RequestMapping("/pageQuerySchool")
    public ReturnResult<MyPage<GoodsDTO>> pageQuerySchool(@RequestBody GoodsRequest goodsRequest){
        return ReturnResultUtils.returnSuccess(goodsService.pageQuerySchool(goodsRequest));
    }

    @RequestMapping("/pageQueryByDetail")
    public ReturnResult<MyPage<GoodsDTO>> pageQueryByDetail(@RequestBody GoodsRequest goodsRequest){
        return ReturnResultUtils.returnSuccess(goodsService.pageQueryByDetail(goodsRequest));
    }

    @RequestMapping("/queryListByFid")
    public ReturnResult<List<GoodsDTO>> queryListByFid(Long fansId){
        return ReturnResultUtils.returnSuccess(goodsService.queryListByFid(fansId));
    }

    @RequestMapping("/queryGoodsById")
    public ReturnResult<GoodsDTO> queryGoodsById(Long goodsId){
        return ReturnResultUtils.returnSuccess(goodsService.queryGoodsById(goodsId));
    }
    @RequestMapping("/publishGoods")
    public ReturnResult<GoodsDTO> publishGoods(@RequestBody GoodsDTO goodsDTO){
        return ReturnResultUtils.returnSuccess(goodsService.publishGoods(goodsDTO));
    }

    @RequestMapping("/updateGoodsState")
    public ReturnResult<Void> updateGoodsState(Long id,GoodsState goodsState){
        goodsService.updateGoodsState(id,goodsState);
        return ReturnResultUtils.returnSuccess(null);
    }

    @RequestMapping("/deleteGoods")
    public ReturnResult<Void> deleteGoods(Long id){
        goodsService.deleteById(id);
        return ReturnResultUtils.returnSuccess(null);
    }

    @RequestMapping("/getBannerList")
    public ReturnResult<List<CosDTO>> getBannerList(){
        return ReturnResultUtils.returnSuccess(cosService.queryBannerList());
    }


}
